import asyncio
import tornado.web
import os
import logging.config
from log import config

logging.config.dictConfig(config)
logger = logging.getLogger(__name__)


class UserHandler(tornado.web.RequestHandler):
    def get(self):
        username_laber = '账号:'
        password_laber = '密码:'
        context = locals()
        context.pop('self')
        self.render('login.html', **context)
    def post(self, *args, **kwargs):
        username = self.get_body_argument('username')
        password = self.get_body_argument('password')
        if username == 'zy' and password == '123456':
            is_login = True
        else:
            is_login = False
            self.set_status(400)
        info = {
            "user": username,
            "is_login": is_login
        }
        self.write(info)

urls = [(r'/', UserHandler), ]
BASR_DIR = os.path.dirname(__file__)
app = tornado.web.Application(urls, template_path=os.path.join(BASR_DIR, 'templates'),
                              cookie_secret="61oETzKXQAGaYdghdhgfhfhfg")
app.listen(8001)

loop = asyncio.get_event_loop()
loop.run_forever()